//====================================================================================================
// Includes
//====================================================================================================

#include "BossIdle.h"

#include "Boss.h"

//====================================================================================================
// Class Definitions
//====================================================================================================

BossIdle::BossIdle(Boss* pOwner)
	: BossState(pOwner, "Idle")
{
	// Empty
}

//----------------------------------------------------------------------------------------------------

BossIdle::~BossIdle()
{
	// Empty
}

//----------------------------------------------------------------------------------------------------

void BossIdle::Load(int level)
{
	mSprite.Add("boss_idle01.png");
}

//----------------------------------------------------------------------------------------------------

void BossIdle::Unload()
{
	mSprite.Unload();
}

//----------------------------------------------------------------------------------------------------

void BossIdle::Update(float deltaTime)
{
	// Update sprite
	mSprite.Update(deltaTime);

	// State transitions
	mDelay -= deltaTime;

	if (mDelay <= 0.0f)
	{
		mpOwner->ChangeState(bAS_Walk);
		mDelay = RandomFloat(1.0f, 10.0f);
	}

	//mpOwner->ChangeState(eAS_Walk);
}

//----------------------------------------------------------------------------------------------------

void BossIdle::Render(const SVector2& offset)
{
	const int kTextureWidth = mSprite.GetWidth();
	const int kTextureHeight = mSprite.GetHeight();
	const SVector2 ownerPos(mpOwner->GetPosition());
	const SVector2 renderPos(ownerPos.x - (kTextureWidth * 0.5f), ownerPos.y - kTextureHeight);
	bool facingLeft = mpOwner->IsFacingLeft();
	mSprite.SetPosition(renderPos - offset);
	mSprite.SetFlipH(facingLeft);
	mSprite.Render();
}

//----------------------------------------------------------------------------------------------------

void BossIdle::Enter()
{
	mSprite.Play(4.0f, true);
}

//----------------------------------------------------------------------------------------------------

void BossIdle::Exit()
{
	mSprite.Stop();
	mSprite.Reset();
}

//----------------------------------------------------------------------------------------------------

SRect BossIdle::GetBoundingBox() const
{
	const SVector2 pos(mpOwner->GetPosition());
	return SRect
	(
		pos.x - 16.0f,
		pos.y - 56.0f,
		pos.x + 16.0f,
		pos.y
	);
}